﻿using System;
using System.Collections.Generic;

namespace ProjectMyFarmAndShe
{
    public class LevelUpItemData
    {
        public int Level = 1;
        public List<LevelItemData> LevelItemDatas;
        //是否已经升级
        public bool IsUp = false;

        public Func<bool> mUnlock;
        private Func<bool> Condition;
        private Action OnFinished;

        public void OnFinish()
        {
            if (Condition())
            {
                OnFinished?.Invoke();
                IsUp = true;
            }
        }

        public LevelUpItemData()
        {
            LevelItemDatas = new List<LevelItemData>();
        }

        public LevelUpItemData WithLevel(int level)
        {
            Level = level;
            return this;
        }

        public LevelUpItemData WithUnLock(Func<bool> unlock)
        {
            mUnlock = unlock;
            return this;
        }

        public LevelUpItemData WithCondition(Func<bool> condition)
        {
            Condition = condition;
            return this;
        }
        
        public LevelUpItemData WithOnFinished(Action finished)
        {
            OnFinished = finished;
            return this;
        }

        public LevelUpItemData AddLevelItemData(string key,int count)
        {
            
            LevelItemDatas.Add(new LevelItemData(key,count));
            return this;
        }
    }
}